// Copyright: 北京经海科技有限公司
// Author: Ivan (李渊)
// Date: 2015-03-01
// Last Modified: 2015-05-22
// Description: 用于显示CCD采集的图像，并可以在上面增加各种标注

#ifndef DISPLAY_WIDGET_H
#define DISPLAY_WIDGET_H

#include <QWidget>
#include <QPoint>
#include <QFont>
#include <QPen>
#include <QColor>
#include <QList>

#include "ImageView.h"
#include "element.h"

const int DEFAULT_LINE_WIDTH = 3;
const int DEFAULT_FONT_SIZE = 18;

class DisplayWidget : public ImageView
{
    Q_OBJECT
public:
    DisplayWidget(ImageView::ImageFormat format = RGB24, QWidget *parent = 0);
    ~DisplayWidget();
    /**
    * @brief 将当前图像保存到文件中
    * @param fileName 带路径的完整文件名
    * @param checked 是否保存标注
    * @return true 表示保存成功，false 表示保存失败
    */	
    bool saveImage(const QString & fileName, bool checked);
	QImage getImage(bool withMark);
    double getLength(bool &ok);
    bool getRectagel(QRect &rect);
    Element *findShape(const QPoint &pt);

private:
    void drawElement(QPainter &painter);
    void mouseLeftButtonPress(QPoint point);
    void mouseRightButtonPress(QPoint point);
public slots:

    void undo(void);
    void clearAll(void);
    void setScale(double scale);
    void setColor(const QColor color);
    void setTextSize(int width);
    void setLineWidth(int width);
    void setDrawType(enum Element::DrawType type);
    void calibrate();
    void setReferenceLine(int pos);
    void addCircle(QPoint center, double radius);

protected:
    void paintEvent(QPaintEvent *event);
    void mousePressEvent(QMouseEvent * event);
    void mouseReleaseEvent(QMouseEvent * event);
    void mouseMoveEvent( QMouseEvent * event);
    //void mouseDoubleClickEvent(QMouseEvent *event);

private:    
    enum Element::DrawType m_drawType;
    QPoint m_startPoint;
    QPen m_linePen;
    QFont m_textFont;
    QList<Element *> m_shapeList;
    Element *pcurrentShape;
    Element *pShapeFind;
    int m_ExtLine;
};
#endif
